package com.yingside.net.chat01;

import com.yingside.net.chat01.ClientFrame;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoginFrame extends JFrame {
	private JPanel panel;
	private JLabel lblName;
	private JTextField txtName;
	private JButton btnSend;
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginFrame frame = new LoginFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public void close(){
		this.dispose();
	}
	public LoginFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(400, 100, 400, 100);
		panel = new JPanel();
		lblName = new JLabel("请输入用户名:");
		txtName = new JTextField(20);
		btnSend = new JButton("登录");
		btnSend.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				String name = txtName.getText();
				if(name == null || name.equals("")){
					JOptionPane.showMessageDialog(null, "用户名不能为空");
					return;
				}
				new ClientFrame(name);
				close();
			}
		});
		panel.add(lblName);
		panel.add(txtName);
		panel.add(btnSend);
		this.add(panel);
		pack();

	}

}
